package cn.xspace.wnx.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;

import com.xspace.android.imcommon.utils.AppUtil;
import com.xspace.android.xafcommon.base.BaseActivity;
import com.xspace.android.xafcommon.base.PagerInfoView;
import com.xspace.android.xafcommon.been.BaseReturnBean;
import com.xspace.android.xafcommon.util.Constants;
import com.xspace.android.xafcommon.util.EventBusConstant;
import com.xspace.android.xafcommon.util.HypyUtil;
import com.xspace.android.xafcommon.util.LogUtil;
import com.xspace.android.xafcommon.util.RequestConstant;
import com.xspace.android.xafcommon.util.ResourceUtils;
import com.xspace.android.xafcommon.view.sdlv.Menu;
import com.xspace.android.xafcommon.view.sdlv.MenuItem;
import com.xspace.android.xafcommon.view.sdlv.SlideAndDragListView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xspace.app.view.TitleBar;
import cn.xspace.chatui.bean.MessageEntity;
import cn.xspace.library.util.MsgType;
import cn.xspace.library.util.MyInfoUtil;
import cn.xspace.library.util.OkHttpManager;
import cn.xspace.wnx.R;
import cn.xspace.wnx.adapter.NoticeOrWNXAdapter;
import cn.xspace.wnx.db.MessageRecordDao;
import cn.xspace.wnx.db.NoticeDao;
import cn.xspace.wnx.db.PreferencesDb;
import cn.xspace.wnx.db.WNXDBManager;
import cn.xspace.wnx.entity.Body;
import cn.xspace.wnx.entity.WNXBean;
import cn.xspace.wnx.util.Navigator;
import de.greenrobot.event.EventBus;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * 通知公告或者微农信的列表界面,微农信点击进去后还有一个微农信信息界面,是WnxOrgMessageListActivity
 * Created by Administrator on 2016/10/17 0017.
 */
public class NoticeOrWNXListActivity extends BaseActivity implements SlideAndDragListView.OnListItemLongClickListener,
        SlideAndDragListView.OnDragListener, SlideAndDragListView.OnSlideListener,
        SlideAndDragListView.OnListItemClickListener, SlideAndDragListView.OnMenuItemClickListener,
        SlideAndDragListView.OnItemDeleteListener, SlideAndDragListView.OnListScrollListener {

    public static final String TAG = NoticeOrWNXListActivity.class.getSimpleName();

    public boolean isVisible;
    protected TitleBar mTitleBar;
    private PagerInfoView mPagerInfo;
    private Menu mMenu;
    private SlideAndDragListView<WNXBean> mListView;
    private NoticeOrWNXAdapter noticeOrWNXAdapter;//weinongxin

    public int msg_type; //0：通知公告；1：微农信；2：单聊；3：群聊
    private ArrayList<WNXBean> noticeOrWNXList = new ArrayList<>();
    private MessageEntity messageEntity;
    private String user_id;
    private boolean isPause = false;

    //拼音首字母排序
    private Comparator<WNXBean> comparator = new Comparator<WNXBean>() {
        @Override
        public int compare(WNXBean lhs, WNXBean rhs) {
            if (TextUtils.isEmpty(lhs.shotKey)) {
                return -1;
            }
            String key1 = lhs.shotKey.toUpperCase();
            Integer num1 = HypyUtil.chartSortMap.get(key1);
            String key2 = rhs.shotKey.toUpperCase();
            Integer num2 = HypyUtil.chartSortMap.get(key2);
            if (num1 == null) {
                return -1;
            }
            if (num2 == null) {
                return 1;
            }
            return num1.compareTo(num2);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        isVisible = true;
    }

    /**
     * 此代码判断是否由后台唤醒进入前台
     */
    @Override
    protected void onResume() {
        super.onResume();
        isVisible = false;
        if (isPause) {
            try {
                if (msg_type == MsgType.WNX_MSG.toNumber()) { //微农信
                    refreshWNXData();
                }
                isPause = false;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
        isPause = true;
    }

    @Override
    protected void getIntentData() {
        super.getIntentData();

        messageEntity = (MessageEntity) getIntent().getExtras().get("MessageEntity");
        String msg_type_temp = getIntent().getStringExtra("msg_type");
        if (!TextUtils.isEmpty(msg_type_temp)) {
            msg_type = Integer.parseInt(msg_type_temp);
        }
        if (messageEntity != null) {
            msg_type = messageEntity.msg_type;
            LogUtil.d(msg_type + "");
        }
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_notice_or_wnx);
    }

    @Override
    protected void initFindViewById() {
        super.initFindViewById();
        mTitleBar = (TitleBar) findViewById(R.id.wnx_or_notice_title_bar);
        mPagerInfo = (PagerInfoView) findViewById(R.id.wnx_pager_info);
        if (msg_type == MsgType.NOTICE.toNumber()) { // 0：通知公告；
            mTitleBar.setTitle(getString(R.string.notice_tell));
        } else { //不是0就是1：微农信
            mTitleBar.setTitle(getString(R.string.weinongxin));
        }
        mListView = (SlideAndDragListView) findViewById(R.id.slv_wnx_or_notice);
        initMenu();
        mListView.setMenu(mMenu);
    }

    /**
     * 侧滑弹出的菜单内的条目
     */
    private void initMenu() {
        mMenu = new Menu(true, true);
        if (msg_type == MsgType.NOTICE.toNumber()) {
            mMenu.addItem(new MenuItem.Builder().setWidth((int) getResources().getDimension(R.dimen.space_49) + 40)
                    .setBackground(ResourceUtils.getDrawable(R.drawable.selector_btn_delete))
                    .setText(getString(R.string.delete)) //删除
                    .setDirection(MenuItem.DIRECTION_RIGHT)
                    .setTextColor(Color.WHITE)
                    .setTextSize(14)
                    .build());
        }
    }

    @Override
    protected void initData() {
        user_id = MyInfoUtil.getMyUserid(mContext);
        noticeOrWNXList = new ArrayList<>();
        noticeOrWNXAdapter = new NoticeOrWNXAdapter(mContext, noticeOrWNXList);
        mListView.setAdapter(noticeOrWNXAdapter);
        mListView.setOnDragListener(this, noticeOrWNXList);

        showWaitDialog();
        if (msg_type == MsgType.NOTICE.toNumber()) { //通知公告
            refreshNoticeData(); //进入页面时加载
        } else {//微农信
            registerSubscription(MessageRecordDao.getInstance().getiMessageData().updateUnreadStatus("", MsgType.WNX_MSG
                    .toNumber())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe());


            if (AppUtil.isConnected(mContext)) { //有网络才去访问
                String isLoad = PreferencesDb.getInstance().queryPreferences("isLoadWnx");//是否加载过微农信列表
                if (TextUtils.isEmpty(isLoad)) { //没有加载过微农信列表
                    requestWNXList(); //没有从网络拉取过数据
                } else {
                    refreshWNXData(); //已经从网络拉取过数据了
                }
            } else {
                refreshWNXData(); //无网络加载本地
            }
        }
    }

    /**
     * 查询微农信机构列表
     */
    private void requestWNXList() {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put(RequestConstant.KEY_USER_ID, user_id);
        registerSubscription(OkHttpManager.getInstance().commonRequest(Constants.QUERY_MICRO_AGRORG, dataMap)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, ArrayList<WNXBean>>() {
                    @Override
                    public ArrayList<WNXBean> call(BaseReturnBean baseReturnBean) {
                        ArrayList<WNXBean> beanList = new ArrayList<>();
                        try {
                            JSONArray jsonArray = new JSONArray(baseReturnBean.data);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObj = jsonArray.optJSONObject(i);
                                WNXBean bean = new WNXBean();
                                bean.msg_sender_id = jsonObj.optString("dept_id");
                                bean.msg_sender_name = jsonObj.optString("dept_name");
                                bean.msg_logo = jsonObj.optString("dept_logo");
                                bean.msg_type = MsgType.WNX_MSG.toNumber();
                                bean.msg_unread_flag = 0;
                                beanList.add(bean);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
//                        WNXBean bean = new WNXBean();
//                        bean.msg_sender_id = "1122221432143222";
//                        bean.msg_sender_name = "啊啊啊啊啊";
//                        bean.msg_type = MessageEntity.MsgType.WNX_MSG.toNumber();
//                        bean.msg_unread_flag = 0;
//                        WNXBean bean1 = new WNXBean();
//                        bean1.msg_sender_id = "112222123123222";
//                        bean1.msg_sender_name = "呵呵呵";
//                        bean1.msg_type = MessageEntity.MsgType.WNX_MSG.toNumber();
//                        bean1.msg_unread_flag = 0;
//                        WNXBean bean2 = new WNXBean();
//                        bean2.msg_sender_id = "214123243215";
//                        bean2.msg_sender_name = "擦双方的但是";
//                        bean2.msg_type = MessageEntity.MsgType.WNX_MSG.toNumber();
//                        bean2.msg_unread_flag = 0;
//                        beanList.add(bean);
//                        beanList.add(bean1);
//                        beanList.add(bean2);
                        return beanList;
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Action1<ArrayList<WNXBean>>() {
                    @Override
                    public void call(ArrayList<WNXBean> wnxBeenList) {
                        ArrayList<WNXBean> localList = WNXDBManager.getInstance().getWnxList();
                        List<Integer> numberList = new ArrayList<Integer>();
                        int number = 0;
                        for (WNXBean wnxBean : wnxBeenList) {
                            for (WNXBean wnxBeanLocal : localList) {
                                if (wnxBeanLocal.msg_sender_id.equals(wnxBean.msg_sender_id)) {
                                    numberList.add(number);
                                }
                            }
                            number++;
                        }
                        LogUtil.d(" numberList " + numberList.size());
                        for (int num : numberList) {
                            if (num < wnxBeenList.size()) {
                                wnxBeenList.remove(num);
                            }
                        }
                    }
                })
                .subscribe(new Subscriber<ArrayList<WNXBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        e.printStackTrace();
                        dealNetWorkError();
                    }

                    @Override
                    public void onNext(final ArrayList<WNXBean> beanList) {
                        hideWaitDialog();
                        LogUtil.d(TAG, "wubaojie>>>onNext: beanList:" + beanList);
                        NoticeDao.getInstance().saveWNXOrgList(beanList)
                                .subscribeOn(Schedulers.io())
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(new Subscriber<String>() {
                                    @Override
                                    public void onCompleted() {

                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        e.printStackTrace();
                                    }

                                    @Override
                                    public void onNext(String s) {
                                        PreferencesDb.getInstance().savePreferences("isLoadWnx", "1");
                                        refreshWNXData();
                                    }
                                });
                    }
                }));
    }

    private void dealNetWorkError() {
        mPagerInfo.showNetWorkError();
    }

    public void refreshWNXData() {
        NoticeDao.getInstance().getData().getWnxList()
                .map(new Func1<ArrayList<WNXBean>, ArrayList<WNXBean>>() {
                    @Override
                    public ArrayList<WNXBean> call(ArrayList<WNXBean> wnxBeen) {
                        ArrayList<WNXBean> list = new ArrayList<>();
                        ArrayList<WNXBean> netList = new ArrayList<>();
                        ArrayList<WNXBean> local = new ArrayList<>();
                        for (WNXBean bean : wnxBeen) {
                            if (bean.bean_type == 1) {
                                netList.add(bean);
                            } else {
                                local.add(bean);
                            }
                        }
                        for (WNXBean bean : netList) {
                            bean.shotKey = HypyUtil.cn2py(bean.msg_sender_name);
                        }
                        Collections.sort(netList, comparator);
                        list.addAll(local);
                        list.addAll(netList);
                        return list;
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<WNXBean>>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        hideWaitDialog();
                    }

                    @Override
                    public void onNext(List<WNXBean> list) {
                        LogUtil.d(TAG, "wubaojie>>>onNext: list:" + list.toString());
                        hideWaitDialog();
                        noticeOrWNXList.clear();
                        noticeOrWNXList.addAll(list);
                        refreshList();
                        if (noticeOrWNXList.size() == 0) {
                            mPagerInfo.showPageEmpty(R.string.wnx_list_empty);
                        } else {
                            mPagerInfo.hiddenPager();
                        }
                    }
                });
    }

    /**
     * 获取通知公告条目
     */
    public void refreshNoticeData() {
        NoticeDao.getInstance().getData().getNoticeList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<WNXBean>>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        hideWaitDialog();
                    }

                    @Override
                    public void onNext(List<WNXBean> list) {
                        hideWaitDialog();
                        noticeOrWNXList.clear();
                        noticeOrWNXList.addAll(list);
                        if (noticeOrWNXList.size() == 0) {
                            mPagerInfo.showPageEmpty(R.string.notice_empty);
                        } else {
                            mPagerInfo.hiddenPager();
                        }
                        refreshList();
                    }
                });
    }

    @Override
    protected void initEvent() {
        mTitleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        // TODO 暂时没用到该界面

        mListView.setOnListItemLongClickListener(this);
        mListView.setOnListItemClickListener(this);
        mListView.setOnSlideListener(this);//左滑删除监听 //需要数据本身有可以左滑删除的属性
        mListView.setOnMenuItemClickListener(this);
        mListView.setOnItemDeleteListener(this);
        mListView.setOnListScrollListener(this);

        mPagerInfo.setOnReloadClickListener(new PagerInfoView.OnReloadClickListener() {
            @Override
            public void onReloadClick(View v) {
                if (msg_type == MsgType.WNX_MSG.toNumber()) {
                    requestWNXList();
                }
            }
        });

    }

    /**
     * eventbus消息接受
     *
     * @param map map中包括type和其他字段。type代表消息类型
     *            type:
     *            AlbumActivity  代表相册
     *            File代表附件
     */
    public void onEventMainThread(Map map) {
        LogUtil.e("eventbus提示你开始刷新了11111：");
        if (EventBusConstant.XMPP_PUSH.equals(map.get(EventBusConstant.TYPE))) {
            Object obj = map.get(EventBusConstant.XMPP_PUSH_BEAN);
            if (obj instanceof WNXBean) {
                WNXBean wnxBean = (WNXBean) obj;
                if (wnxBean.msg_type == messageEntity.msg_type) {
//                    pushRefresh(wnxBean);
                    refreshWNXData();
                }
            }
        } else if (EventBusConstant.CLEAR_WNX_OR_NOTICE.equals(map.get(EventBusConstant.TYPE))) {
//            LogUtil.d(TAG, "wubaojie>>>onEventMainThread: 刷新界面");
//            refreshWNXData();
        }
    }

    private void refresh() {
        if (noticeOrWNXAdapter != null) {
            noticeOrWNXAdapter.notifyDataSetChanged();
        }
    }

    private void pushRefresh(WNXBean wnxBean) {
        LogUtil.d(wnxBean.toString());
        boolean isSended = false;
        int index = -1;
        WNXBean wnxbeanOld = null;
        for (WNXBean bean : noticeOrWNXList) {
            if (bean.msg_sender_id.equals(wnxBean.msg_sender_id)) {
                isSended = true;
                wnxbeanOld = bean;
                index = noticeOrWNXList.indexOf(bean);
            }
        }
        LogUtil.d(" isSended ?" + isSended);
        if (isSended) {
            noticeOrWNXList.remove(wnxbeanOld);
            wnxBean.unreadCount = wnxbeanOld.unreadCount + 1;
        }
        noticeOrWNXList.add(0, wnxBean);
        noticeOrWNXAdapter.notifyDataSetChanged();
        LogUtil.d(" noticeOrWNXList ?" + noticeOrWNXList.toString());
    }

    /**
     * 刷新列表的方法
     */
    private void refreshList() {
        noticeOrWNXAdapter.notifyDataSetChanged();
    }


//    Subscriber<List<WNXBean>> subscriber = ;

    @Override
    public void onListItemLongClick(View view, int position) {
        Log.i(TAG, "onListItemLongClick   " + position);
    }

    @Override
    public void onDragViewStart(int position) {
        Log.i(TAG, "onDragViewStart   " + position);
    }


    @Override
    public void onDragViewMoving(int position) {
        Log.i("yuyidong", "onDragViewMoving   " + position);
    }

    @Override
    public void onDragViewDown(int position) {
        Log.i(TAG, "onDragViewDown   " + position);
    }

    @Override
    public void onListItemClick(View v, int position) {
        int index = position - mListView.getHeaderViewsCount();
        Log.i(TAG, "onListItemClick   " + index);
        WNXBean wnxBean = noticeOrWNXList.get(index);
        if (wnxBean.msg_type == MsgType.WNX_MSG.toNumber()) {
            //将其设为已读
            wnxBean.unreadCount = 0;
            Navigator.startWnxListActivity(mContext, wnxBean);
        } else {
            if (wnxBean.msg_unread_flag == 0) {
                Map<String, Object> params = new HashMap<>();
                params.put("user_id", MyInfoUtil.getMyUserid(mContext));
                params.put("msg_id", wnxBean.msg_id);
                registerSubscription(OkHttpManager.getInstance().commonRequest(Constants.UPDATE_USER_MSGSTATE, params)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe());
                wnxBean.msg_unread_flag = 1;
                NoticeDao.getInstance().getData().updateWnxRecordReadStatus(wnxBean.inserttime,
                        MsgType.NOTICE.toNumber())
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Action1<String>() {
                            @Override
                            public void call(String s) {
                                LogUtil.d(TAG, "wubaojie>>>call: 刷新列表");
                                refreshNoticeData();
                            }
                        });
            }
            Body.NewssnapBean newBean = null;
            try {
                JSONArray jsonArray = new JSONArray(wnxBean.content);
                if (jsonArray.length() > 0) {
                    JSONObject jsonObject = jsonArray.getJSONObject(0);
                    newBean = new Body.NewssnapBean(jsonObject);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (newBean != null) {
//                newBean.getTitle()
                Navigator.startWnxWebView(mContext, newBean.getSrc(), "", wnxBean.msg_sender_id,
                        MsgType.NOTICE.toNumber());
            }
        }
        noticeOrWNXAdapter.notifyDataSetChanged();
//        if (msg_type.equalsIgnoreCase("0")) {
//            com.cn.wt.wtutils.log.LogUtils.e("开始跳转页面0");
//            myIntent = new Intent(mContext, NoticeInfoActivity.class);
//            myIntent.putExtra("msgId", noticeOrWNXList.get(position).getMsgId());
//            myIntent.putExtra("userId", noticeOrWNXList.get(position).getUserId());
//            myIntent.putExtra("MessageEntity", messageEntity);
//            myIntent.putExtra("isRead", noticeOrWNXList.get(position).isRead() + "");
//            startActivity(myIntent);
//        } else {
//
//        }
    }

    @Override
    public void onSlideOpen(View view, View parentView, int position, int direction) {
        Log.i(TAG, "onSlideOpen   " + position);
    }

    @Override
    public void onSlideClose(View view, View parentView, int position, int direction) {
        Log.i(TAG, "onSlideClose   " + position);
    }

    @Override
    public int onMenuItemClick(View v, int itemPosition, int buttonPosition, int direction) {
        Log.i(TAG, "onMenuItemClick   " + itemPosition + "   " + buttonPosition + "   " + direction);
        final int position = itemPosition - mListView.getHeaderViewsCount();
        LogUtil.e(TAG, "wubaojie>>>" + "onMenuItemClick: " + position);
        switch (direction) {
            case MenuItem.DIRECTION_LEFT:
                switch (buttonPosition) {
                    case 0:
                        return Menu.ITEM_NOTHING;
                    case 1:
                        return Menu.ITEM_SCROLL_BACK;
                }
                break;
            case MenuItem.DIRECTION_RIGHT:
                switch (buttonPosition) {
                    case 0:
                        try {
                            WNXBean deleteWNXBean = noticeOrWNXList.get(itemPosition);
                            noticeOrWNXList.remove(itemPosition);
                            noticeOrWNXAdapter.notifyDataSetChanged();
                            if (deleteWNXBean.msg_type == MsgType.NOTICE.toNumber()) { //通知可以删除
                                registerSubscription(NoticeDao.getInstance().getData().deleteWnxNotice(deleteWNXBean)
                                        .observeOn(Schedulers.io())
                                        .subscribe());

                            } else {

                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

//                        if (deleteWNXBean.msg_type == MessageEntity.MsgType.NOTICE.toNumber()) {
//                            MessageRecordDao.getInstance().getiMessageData().deleteSingleChat(deleteWNXBean
//                                    .msg_sender_id)
//                                    .observeOn(Schedulers.io())
//                                    .subscribe(commonAction);
////            MessageRecordDao.getInstance().deleteSingleChat(deleteEntity.msg_sender_id);
//                        } else {
//                            MessageRecordDao.getInstance().getiMessageData().deleteGroupChat(deleteEntity
// .msg_group_id)
//                                    .observeOn(Schedulers.io())
//                                    .subscribe(commonAction);
////            MessageRecordDao.getInstance().deleteGroupChat(deleteEntity.msg_group_id);
//                        }
                        return Menu.ITEM_SCROLL_BACK;
                    case 1:
                        return Menu.ITEM_DELETE_FROM_BOTTOM_TO_TOP;
                }
        }
        return Menu.ITEM_NOTHING;
    }

    @Override
    public void onItemDelete(View view, int position) {
        noticeOrWNXList.remove(position - mListView.getHeaderViewsCount());
        noticeOrWNXAdapter.notifyDataSetChanged();
    }


    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        switch (scrollState) {
            case SlideAndDragListView.OnListScrollListener.SCROLL_STATE_IDLE:
                break;
            case SlideAndDragListView.OnListScrollListener.SCROLL_STATE_TOUCH_SCROLL:
                break;
            case SlideAndDragListView.OnListScrollListener.SCROLL_STATE_FLING:
                break;
        }
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    }

    private void setWnxRead() {
        registerSubscription(MessageRecordDao.getInstance().getiMessageData().updateUnreadStatus("", MsgType.WNX_MSG
                .toNumber())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe());
    }

}
